package com.xiaoyu.lanling.feature.conversation.model

import `in`.srain.cube.views.list.ListItemTypedBase
import com.xiaoyu.lanling.feature.conversation.viewholder.ConversationListViewHolderManager

abstract class ConversationListItemBase : Comparable<ConversationListItemBase>, ListItemTypedBase {

    open val newTipCount: Int
        get() = 0

    override fun compareTo(other: ConversationListItemBase): Int {
        var level = 1
        while (true) {
            val result = other.getCompareValue(level).compareTo(getCompareValue(level))
            if (result != 0 || ++level > MAX_COMPARE_VALUE) {
                return result
            }
        }
    }

    protected open fun getCompareValue(level: Int): Long {
        return if (level == 1) ConversationListViewHolderManager.getWeight(this).toLong() else 0
    }

    companion object {
        private const val MAX_COMPARE_VALUE = 2
    }
}